<?php
require_once 'exceptions/no-such-class.php';
use \phiction\exceptions\no_such_class;

// autoload example:
//   \name\space\class_name => name/space/class-name.php
//
// autoload rule:
//   to lowercase
//   '\\' => '/'
//   '_' => '-'
//   append ".php"
//
spl_autoload_register(function ($class) {
    $path = str_replace(['\\', '_'], ['/', '-'], strtolower($class)) . ".php";
    if (!file_exists($path)) throw new no_such_class("class not found: $class");
    try {
        require_once $path;
    }
    catch (no_such_class $ex) { // class not found inside loaded class is considered internal server error
        throw new \Exception($ex);
    }
});

